package com.example.listener;

import cn.hutool.json.JSONUtil;
import com.example.message.User;
import com.fanxuankai.zeus.canal.mq.support.annotation.*;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;

/**
 * @author zxs
 * @since 2021/6/8
 */
@RocketMQMessageListener(topic ="test" ,selectorExpression = "object",consumerGroup = "user")
@CanalListener(topic = "mysql",entityClass = User.class)
public class UserCanalListener {

    @Insert
    public void insert(User user){
        System.out.println("---insert---:"+JSONUtil.toJsonStr(user));
    }


    @Update
    public void update(User oldUser,User newUser){
        System.out.println("---update old---:"+JSONUtil.toJsonStr(oldUser));
        System.out.println("---update new---:"+JSONUtil.toJsonStr(newUser));
    }

    @Delete
    public void delete(User user){
        System.out.println("---delete---:"+JSONUtil.toJsonStr(user));
    }

    @BeforeUpdate
    public void beforeUpdate(User oldUser){
        System.out.println("---before update---:"+JSONUtil.toJsonStr(oldUser));
    }

    @AfterUpdate
    public void afterUpdate(User newUser){
        System.out.println("---after update---:"+JSONUtil.toJsonStr(newUser));
    }
}
